using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class CreatePlayerPanel : BasePanel
{
    [SerializeField] private PlayerData playerData;
    [SerializeField] private Button startGame;

    [SerializeField] private Button returnButton;

    [SerializeField] private TMP_InputField inputName;
    
    //
    
    
    //
    private void Start()
    {
        startGame.onClick.AddListener(StartGame);
        returnButton.onClick.AddListener(ReturnAction);
    }

    //
    private void StartGame()
    {
        // 获取输入的 用户名
        playerData.playerName = inputName.text;
        // 血量最大值，分数为零
        playerData.playerBlood = playerData.GetPlayerBloodMax;
        playerData.playerScore = 0;
        // 第一关，教学关卡
        playerData.sceneIndex = 1;
        // 加载场景
        EventCenter.Instance.EventTrigger(EventName.EVENT_SCENE_SCENESWITE, playerData.sceneIndex);
        // 创建存档
        SaveDataSystem.SaveByJson(playerData.playerName, playerData);
        // 关闭 页面
        UIManager.Instance.ClosePanel(UIConst.PANEL_CREATE);
    }
    
    //
    private void ReturnAction()
    {
        //
        UIManager.Instance.ClosePanel(UIConst.PANEL_CREATE);
    }
}
